//你的代码将被嵌入在这里
#include <iostream>
using namespace std;

class TDshape
{
public:
    virtual float area()=0;
    virtual void printName()=0;
};

class Triangle:public TDshape
{
private:
    float width,height;
public:
    Triangle(float w,float h):width(w),height(h){};
    Triangle(){};
    virtual float area()
    {
        return width*height/2;
    }
    virtual void printName()
    {
        cout<<"Triangle"<<endl;
    }
    void setWidth(float i)
    {
        width=i;
    }
    void setHeight(float i)
    {
        height=i;
    }
};

class Rectangle:public TDshape
{
private:
    float width,height;
public:
    Rectangle(float w,float h):width(w),height(h){}
    Rectangle(){};
    virtual float area()
    {
        return width*height;
    }
    virtual void printName()
    {
        cout<<"Rectangle"<<endl;
    }
    void setWidth(float i)
    {
        width=i;
    }
    void setHeight(float i)
    {
        height=i;
    }

};



void fp(TDshape *p);
void fr(TDshape &r);
int main()
{
    Triangle triangle(3,4);//width为3,height为4
    Rectangle rectangle(4,9);//width为4,height为9

    rectangle.setWidth(10);
    cout<<"******from fp:"<<endl;
    fp(&triangle);
    fp(&rectangle);
    cout<<"******from fr:"<<endl;
    fr(triangle);
    fr(rectangle);
    return 0;
}
void fp(TDshape *p)
{
    cout<<"area:"<<p->area()<<endl;
    p->printName();
}
void fr(TDshape &r)
{
    cout<<"area:"<<r.area()<<endl;
    r.printName();
}